/*
 * @file iso9660_dbg.h
 *
 *  Debug handlers for the ISO9660 filesystem
 *
 */

#ifndef __ISO9660_DBG_H_
#define __ISO9660_DBG_H_

#include <rtems/seterr.h>
#include <inttypes.h>

/* Activate ISO9660 debug if unspecified */
#ifndef RTEMS_ISO9660_DEBUG
#define RTEMS_ISO9660_DEBUG 1
#endif

typedef uint64_t rtems_iso9660_dbg_mask_t;

/* Available debug sections for the trace mask */
#define RTEMS_ISO9660_DEBUG_ALL             (0xFFFFFFFFUL)
#define RTEMS_ISO9660_DEBUG_NONE            (0)
#define RTEMS_ISO9660_DEBUG_FSMOUNT         (1UL << 0)
#define RTEMS_ISO9660_DEBUG_FSUNMOUNT       (1UL << 1)
#define RTEMS_ISO9660_DEBUG_SECTOR_READ     (1UL << 2)
#define RTEMS_ISO9660_DEBUG_BUFFER_ACQUIRE  (1UL << 3)
#define RTEMS_ISO9660_DEBUG_BUFFER_RELEASE  (1UL << 4)
#define RTEMS_ISO9660_DEBUG_DEVICEIO        (1UL << 5)
#define RTEMS_ISO9660_DEBUG_RECORD_CREATE   (1UL << 6)
#define RTEMS_ISO9660_DEBUG_RECORD_COPY     (1UL << 7)
#define RTEMS_ISO9660_DEBUG_RECORD_FREE     (1UL << 8)
#define RTEMS_ISO9660_DEBUG_RECORD_OPEN     (1UL << 9)
#define RTEMS_ISO9660_DEBUG_RECORD_CLOSE    (1UL << 10)
#define RTEMS_ISO9660_DEBUG_RECORD_NEXT     (1UL << 11)
#define RTEMS_ISO9660_DEBUG_OPEN            (1UL << 12)
#define RTEMS_ISO9660_DEBUG_CLOSE           (1UL << 13)
#define RTEMS_ISO9660_DEBUG_READ            (1UL << 14)
#define RTEMS_ISO9660_DEBUG_STAT            (1UL << 15)
#define RTEMS_ISO9660_DEBUG_JOLIET          (1UL << 16)
#define RTEMS_ISO9660_DEBUG_SUSP            (1UL << 17)
#define RTEMS_ISO9660_DEBUG_RRIP            (1UL << 18)
#define RTEMS_ISO9660_DEBUG_FILENAME        (1UL << 19)
#define RTEMS_ISO9660_DEBUG_EVAL_PATH       (1UL << 19)

#define RTEMS_ISO9660_DEBUG_DEFAULT         RTEMS_ISO9660_DEBUG_NONE

#define RTEMS_ISO9660_DEBUG_EXTENSIONS    ( RTEMS_ISO9660_DEBUG_JOLIET \
                                           | RTEMS_ISO9660_DEBUG_SUSP   \
                                           | RTEMS_ISO9660_DEBUG_RRIP   )

#if RTEMS_ISO9660_DEBUG
# define rtems_iso9660_error_and_return_minus_one(_c, _e) do { printf("iso9660 error: %s\n", _e); rtems_set_errno_and_return_minus_one(_c); } while (0)
# define rtems_iso9660_error_and_return_null(_c, _e) do { printf("iso9660 error: %s\n", _e); errno = (_c); return NULL; } while (0)
#else
# define rtems_iso9660_error_and_return_minus_one(_c, _e) rtems_set_errno_and_return_minus_one(_c)
# define rtems_iso9660_error_and_return_null(_c, _e) do { errno = (_c); return NULL; } while (0)
#endif

#if RTEMS_ISO9660_DEBUG
# ifdef __cplusplus
extern "C" {
# endif

uint8_t
rtems_iso9660_section_traced(
    rtems_iso9660_dbg_mask_t section
);

void
rtems_iso9660_dbg_set_trace(
    rtems_iso9660_dbg_mask_t mask
);

void
rtems_iso9660_dbg_section_enable(
    rtems_iso9660_dbg_mask_t section
);

void
rtems_iso9660_dbg_section_disable(
    rtems_iso9660_dbg_mask_t section
);

rtems_iso9660_dbg_mask_t
rtems_iso9660_dbg_get_mask(
    void
);

void
rtems_iso9660_dbg_trace(
    rtems_iso9660_dbg_mask_t section,
    char *format,
    ...
);

void
rtems_iso9660_dbg_string(
    char *string,
    size_t len
);

# ifdef __cplusplus
}
# endif
#else
# define rtems_iso9660_section_traced(_s)
# define rtems_iso9660_dbg_set_trace(_m)
# define rtems_iso9660_dbg_section_enable(_s)
# define rtems_iso9660_dbg_section_disable(_s)
# define rtems_iso9660_dbg_get_mask()
# define rtems_iso9660_dbg_trace(_i, _f, ...)
#endif


#endif /* __ISO9660_DBG_H_ */
